home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12187 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.5 KB  |  132 lines

  1. Path: dfw.dfw.net!not-for-mail
  2. From: ftlgeuse@dfw.dfw.net (Azazel Diabolus            (aka Fetelgeuse))
  3. Newsgroups: comp.lang.c
  4. Subject: RE: Hiding a password
  5. Date: 27 Mar 1996 18:13:50 GMT
  6. Organization: DFW Internet Services - DFWNet: 800-2-DFWNet
  7. Message-ID: <4jc0gu$crg@fnord.dfw.net>
  8. NNTP-Posting-Host: dfw.dfw.net
  9. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  10.  
  11. tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya) wrote:
  12.  
  13. >In article <4hehmd$1fr@fnord.dfw.net>
  14. >ftlgeuse@dfw.dfw.net (Fetelgeuse) writes:
  15. >
  16. ><snip>
  17. >F: I wrote a function to do precisely the same thing. I made a function
  18. >F: something like:
  19. >F: char * GetString_NoEcho()
  20. >F: {
  21. >F:   char *temp;
  22. >F:   int i=1;
  23. >F:   while(temp[i-1]!=13) {
  24. >F:     temp[i-1]=getch();  
  25. >F:     i++;
  26. >F:   }
  27. >F:   temp[i]=0;
  28. >F: }
  29. >
  30. >Please test your solutions before you post them. I tried the following
  31. >program: 
  32. >
  33. <CODE SIMILAR TO ABOVE REMOVED FOR BREVITY>
  34. >
  35. >When I tried to compile it, I get
  36. >
  37. >j.c:3: warning: function declaration isn't a prototype
  38. >j.c: In function `GetString_NoEcho':
  39. >j.c:7: warning: implicit declaration of function `getch'
  40. >j.c:4: warning: `temp' might be used uninitialized in this function
  41. >j.c:11: warning: control reaches end of non-void function
  42. >j.c: In function `main':
  43. >j.c:13: warning: `pwd' might be used uninitialized in this function
  44. >j.c:4: warning: `temp' might be used uninitialized in this function
  45. >ld: Undefined symbol 
  46. >   _getch 
  47. >
  48. >and I get no executable.
  49. >
  50. >Can you help me? Any idea what I am doing wrong? Should I change the
  51. >i-1 to i*=+5 to get it to work?
  52. >
  53. >If you haven't, please remember that when you post something that is
  54. >wrong, you confuse a lot of other people. If you are merely trying to
  55. >learn, please ask questions: do not pretend to know the answer when
  56. >you don't.
  57. >
  58. >Cheers
  59. >Tanmoy
  60. >--
  61. >
  62.  
  63. OK, Tanmoy, there is no need to be such a smart-ass. The code I posted was
  64. a mere "snippet" to give the original poster and idea of the "theory" of
  65. my suggestion. I openly admitted that the code verbatim probably would not
  66. do the trick which is why I explained what it was doing. It is not up to me
  67. to ensure that each reader knows how to properly prototype his/her functions,
  68. or knows which header files to include for a given function (i.e. getch())
  69.  
  70. Also, the compiler the reader chooses is obviously going to make a difference
  71. so I will remember to include which compiler I succesfully used with any
  72. future code references to prevent the onslaught of nitpicking egoists from 
  73. flooding my mailbox with things like "that won't work! Jeez you're dumb." 
  74.  
  75. Anyone with at least half a brain would have read on after the code and seen
  76. where I said that I typed it quickly and there are probably mistakes, it was
  77. just there to give the reader an IDEA so they could write there own code. But 
  78. for everyone who did not like my advice to the original poster, here is the
  79. code I was describing that will work if it is typed in EXACTLY as I have 
  80. typed it. Also, I compiled it with Borland's Turbo C/C++ v3.0 for DOS. 
  81.  
  82. To save the typing of those who wish to pick apart my friendly advice:
  83. This code is not a tutorial in encryption or security, it is just meant to
  84. show the original poster a way he can get input from the keyboard without
  85. having it echoed to the screen! (I wrote it merely because I did not like
  86. the limitiation of my compilers version of a function in conio.h called 
  87. getpass() which limits the input to 8 characters. I also realize that the
  88. buffer could overflow causing problems but on my computer using this function
  89. I have input 300 characters without a problem- I haven't tried any more 
  90. than that) 
  91.  
  92. Here it is, like it or not:
  93.  
  94. /*-----------------------BEGIN CODE-----------------*/
  95.  
  96. #include<stdio.h>
  97. #include<conio.h>
  98.  
  99. char *getstring_noecho()
  100. {
  101.   char *string;
  102.   int i=0;
  103.   _setcursortype(0);
  104.   while(string[i-1]!=13) {
  105.     string[i++]=getch();
  106.   }
  107.   string[i-1]=NULL;
  108.   return(string);
  109. }
  110.  
  111. void main()
  112. {
  113.   char *password;
  114.   printf("Enter password:");
  115.   password=getstring_noecho();
  116.   printf("%s",password);
  117. }
  118.  
  119. /*-----------------------END CODE-----------------*/
  120.  
  121. If you want to rag on this go ahead but remember that it was only meant as
  122. a nice gesture to the person who had asked for a way to get input from the 
  123. keyboard without having it echoed to the screen; I gave him a way. That
  124. is the only thing this code is meant to do so for everyone who sits around
  125. waiting to harp on someones code they dislike - get a life; if you don't
  126. like someone's advice to someone else, give better advice or shut up!
  127.  
  128. Oh, and Tanmoy, don't pretend to have a clue when you don't.
  129.  
  130. Fetelgeuse.
  131.  
  132.